import { defineStore } from 'pinia';
import { ref } from 'vue';

export const useTabbarStore = defineStore('tabbar', () => {
    const active = ref(0); // 默认选中首页（索引0）

    // 根据路径更新选中状态
    const setActiveByPath = (path) => {
        if (path.startsWith('/cqust/index')) {
            active.value = 0;
        } else if (path.startsWith('/cqust/jsjl')) {
            active.value = 1;
        } else if (path.startsWith('/cqust/yrcg')) {
            active.value = 2;
        } else if (path.startsWith('/cqust/userinfo')) {
            active.value = 3;
        } else {
            // 其他路径默认不选中
            active.value = -1; // 或者保持上一次状态
        }
    };

    return {
        active,
        setActiveByPath,
    };
});
